﻿using System;
using System.Collections;
using System.Xml.Serialization;

namespace ABC.XPath.Test.Models
{
	[XmlRoot("Requirement", Namespace = "http://emsinet.com/schemas/Order/Data")]
	public class Requirement
	{
		private int _id;
		private Order _order;
		private RequirementType _type;
		private string _clientUniqueId;
		private string _processingUniqueId;
		private DateTime _requestedDate;
		private DateTime _completedDate;
		private RequirementState _state;
		private IDictionary _events;

		/// <summary>
		/// Gets/sets the requirement type id.
		/// </summary>
		[XmlIgnore]
		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		/// <summary>
		/// Gets/set the order this requirement belongs to.
		/// </summary>
		[XmlIgnore]
		public Order Order
		{
			get { return _order; }
			set
			{
				_order = value;
				if (!(_order == null || _order.Requirements.Contains(this)))
				{
					_order.Requirements.Add(this, this);
				}
			}
		}

		/// <summary>
		/// Gets/sets the requirement type.
		/// </summary>
		[XmlElement("Type", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public RequirementType Type
		{
			get { return _type; }
			set { _type = value; }
		}

		/// <summary>
		/// Gets/set the clients unique id.
		/// </summary>
		[XmlElement("ClientUniqueId", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public string ClientUniqueId
		{
			get { return _clientUniqueId; }
			set { _clientUniqueId = value; }
		}

		/// <summary>
		/// Gets/sets the requested date.
		/// </summary>
		[XmlIgnore]
		public DateTime RequestedDate
		{
			get { return _requestedDate; }
			set { _requestedDate = value; }
		}

		/// <summary>
		/// Gets/sets the completed date.
		/// </summary>
		[XmlIgnore]
		public DateTime CompletedDate
		{
			get { return _completedDate; }
			set { _completedDate = value; }
		}

		/// <summary>
		/// Gets/set the processing unique id.
		/// </summary>
		[XmlElement("ProcessingUniqueId", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public string ProcessingUniqueId
		{
			get { return _processingUniqueId; }
			set { _processingUniqueId = value; }
		}

		/// <summary>
		/// Gets/set the requirements state.
		/// </summary>
		[XmlElement("State", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public RequirementState State
		{
			get
			{
				if (_state == null)
					_state = new RequirementState();
				return _state;
			}
			set { _state = value; }
		}

		/// <summary>
		/// Gets/sets the requirement events.
		/// </summary>
		[XmlIgnore]
		public IDictionary Events
		{
			get
			{
				if (_events == null)
					_events = new Hashtable();
				return _events;
			}
			set { _events = value; }
		}
	}
}
